{extend name="Layout/index" /}

{block name="main"}
<div style="margin: 15px;">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>修改角色权限</legend>
    </fieldset>

    <form class="layui-form" action="{:url('role/perm_store')}" method="POST">
        <input type="hidden" name="id" value="{$id}">
        {foreach $permissions as $k => $v}
        <div class="layui-form-item">
            <label class="layui-form-label"></label>
            <div class="layui-input-block">
                <input type="checkbox" name="perm[]" title="{$v.description}" value="{$v.id}" {:in_array($id,$v->roles->column('id')) ? 'checked' : '' } >
                {if $v->child}
                {foreach $v->child as $ko => $vo}
                <input type="checkbox" name="perm[]" title="{$vo.description}" value="{$vo.id}" {:in_array($id,$vo->roles->column('id')) ? 'checked' : '' }>
                {/foreach}
                {/if}
            </div>
        </div>
        {/foreach}
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="demo1">提交</button>
                <a href="{:url('role/index')}" class="layui-btn layui-btn-primary">返回</a>
            </div>
        </div>
    </form>
</div>
{/block}

{block name="footer"}
<script>
    layui.use(['form', 'layedit', 'laydate'], function() {
        var form = layui.form,
            layer = layui.layer,
            layedit = layui.layedit,
            laydate = layui.laydate;

        //创建一个编辑器
        var editIndex = layedit.build('LAY_demo_editor');
        //自定义验证规则
//        form.verify({
//            title: function(value) {
//                if(value.length < 5) {
//                    return '标题至少得5个字符啊';
//                }
//            },
//            description: [/(.+){6,12}$/, '密码必须6到12位'],
//            content: function(value) {
//                layedit.sync(editIndex);
//            }
//        });

        //监听提交
//        form.on('submit(demo1)', function(data) {
//            layer.alert(JSON.stringify(data.field), {
//                title: '最终的提交信息'
//            })
//            return false;
//        });
    });
</script>
{/block}